package vn.edu.saigontech.ncms.web.offering;

import vn.edu.saigontech.ncms.model.info.OfferingMember;
import vn.edu.saigontech.ncms.service.OfferingMemberService;
import vn.edu.saigontech.ncms.util.Checker;
import vn.edu.saigontech.ncms.web.AbstractValidator;

@SuppressWarnings("serial")
public class ValidateAbsenceAction extends AbstractValidator {
	private Long id;
	private Long memberId;
	private String numOfAbsentDays;
	private String contactingDate;
	private String reason;
	
	@Override
	public String check() {
		OfferingMember member = OfferingMemberService.INSTANCE.findById(this.memberId);
		if(Checker.isNull(member)) {
			this.sendKeyError("validator.required", "student");
		}
		if(!Checker.isInteger(numOfAbsentDays)) {
			this.sendKeyError("validator.required", "absence.days");
		}
		if (Checker.isEmpty(this.contactingDate)) {
			this.sendKeyError("validator.required", "contactingDate");
		}
		if (!Checker.isDate(this.contactingDate, this.i18n("format.date"))) {
			this.sendKeyError("validator.mask", "contactingDate", "format.date");
		}
		if(Checker.isEmpty(reason)) {
			this.sendKeyError("validator.required", "reason");
		}
		return this.toSuccess();
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getNumOfAbsentDays() {
		return numOfAbsentDays;
	}

	public void setNumOfAbsentDays(String numOfAbsentDays) {
		this.numOfAbsentDays = numOfAbsentDays;
	}

	public String getContactingDate() {
		return contactingDate;
	}

	public void setContactingDate(String contactingDate) {
		this.contactingDate = contactingDate;
	}

	public String getReason() {
		return reason;
	}

	public void setReason(String reason) {
		this.reason = reason;
	}

	public Long getMemberId() {
		return memberId;
	}

	public void setMemberId(Long memberId) {
		this.memberId = memberId;
	}
}
